home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 7675 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: sn.no!not-for-mail
  2. From: oddhs@sn.no (Odd H. Sandvik)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: Randomness
  5. Date: 19 Apr 1996 21:08:25 +0200
  6. Organization: SN Internett
  7. Message-ID: <4l8ob9$22k@sinsen.sn.no>
  8. References: <451.6681T677T994@summat.demon.co.uk>
  9. NNTP-Posting-Host: sinsen.sn.no
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Mike Dodd (mike@summat.demon.co.uk) wrote:
  13. : Help !,
  14.  
  15. : Has anyone got a good algorithm for quickly calculating a "random" number ?
  16.  
  17. Check this out from P. Hanevold. Mind you, I haven't tried it.
  18. From: patrick.hanevold@login.eunet.no (Patrick Hanevold)
  19.  
  20. ; By Patrick Hanevold 5/1-1996
  21.  
  22. SetSeed MACRO
  23.         move.w  \1,rndbuf
  24.         ENDM
  25.  
  26. RND     MACRO
  27.         move.w  (a0),\1
  28.         move.w  2(a0,\1.l*2),\1
  29.         move.w  \1,(a0)
  30.         ENDM
  31.  
  32. Test    SetSeed #1996
  33.         bsr     InitRND
  34.         lea     rndbuf,a0
  35.         clr.l   d0
  36.         RND     d0
  37.         rts
  38.  
  39. InitRND lea     rndbuf,a0
  40.         move.w  (a0)+,d0        ; Seed
  41.         move.w  #-1,d7
  42.         moveq   #0,d1
  43. .loop   move.w  d0,d1
  44.         mulu    #9377,d0
  45.         add.w   #9439,d0
  46.         move.w  d0,(a0,d1.l*2)
  47.         dbra    d7,.loop
  48.         rts
  49.  
  50.         section BSS,BSS
  51. rndbuf  ds.w    $10001
  52.  
  53. -- 
  54. % Odd H. Sandvik %% email: oddhs@sn.no + member Team AMIGA +
  55. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  56. % Acceleration into temporal space continuum now begins...
  57. % Alpha 7, acknowledge... Alpha 7, acknowledge...
  58.